const axios = require("axios").default;

function getBaseURL() {
  return "hhttp://apisp-test.banggood.cn/listing";
}

function request(config) {
  let defaultConfig = {
    timeout: 30000,
    withCredentials: true,
    validateStatus: function (status) {
      return status >= 200 && status < 300; // 默认值
    },
  };
  let options = {
    baseURL: getBaseURL(),
    transformResponse: [], // 处理返回值
    ...defaultConfig,
  };
  return new Promise((res, rej) => {
    axios({
      ...config,
      ...options,
    })
      .then((response) => {
        res(response);
      })
      .catch((error) => {
        rej(error);
      });
  });
}

function getFilterByCode(paramsOrData, options) {
  return request({
    url: "/sku_on_sale/getFilterByCode",
    method: "get",
    // data: paramsOrData,
    params: paramsOrData,
    ...options,
  });
}

getFilterByCode(
  { code: "sale_status" },
  {
    headers: {
      platformNo: 36,
      Cookie:
        'SCB_SESSION_ID=464edb411a3042539c3e530e0add1795; Authorization="Bearer AT-1762-zwQBVECIk9nSPAM2T0aFj7Fh_ZGSdrOy"',
    },
  }
).then((res) => {
  console.log(res.data);
});
